//
//  LZSettingViewController.m
//  LZBS
//
//  Created by 郝庆 on 16/6/8.
//  Copyright © 2016年 haoqing. All rights reserved.
//

#import "LZSettingViewController.h"
#import "LZSettingCell.h"
#import "LZOtherCell.h"
#import "LZClearCacheCell.h"

@interface LZSettingViewController ()

@end

@implementation LZSettingViewController
static NSString * const LZSettingCellId = @"LZSettingCell";
static NSString * const LZOtherCellId = @"LZOtherCell";
static NSString * const LZClearCacheCellId = @"LZClearCacheCell";

#pragma mark - 设置tabView样式为分组样式
- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[LZSettingCell class] forCellReuseIdentifier:LZSettingCellId];
    [self.tableView registerClass:[LZOtherCell class] forCellReuseIdentifier:LZOtherCellId];
    [self.tableView registerClass:[LZClearCacheCell class] forCellReuseIdentifier:LZClearCacheCellId];
    
}

#pragma mark - 数据源方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 2;
    }else {
        return 7;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        LZSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:LZSettingCellId];
        if (indexPath.row == 0) {
            NSArray *segmentedData = [[NSArray alloc]initWithObjects:@"小",@"中",@"大",nil];
            UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedData];
            // 默认选择第0个
            segmentedControl.selectedSegmentIndex = 0;
            cell.textLabel.text = @"字体大小";
            cell.accessoryView = segmentedControl;
        }else{
            cell.textLabel.text = @"摇一摇夜间模式";
            cell.accessoryView = [[UISwitch alloc] init];
        }
        return cell;
    }else{
        if (indexPath.row == 0) {
            LZClearCacheCell *cell = [tableView dequeueReusableCellWithIdentifier:LZClearCacheCellId];
            
            return cell;
        } else {
            
            LZOtherCell *cell = [tableView dequeueReusableCellWithIdentifier:LZOtherCellId];
            if (indexPath.row == 1) {
                cell.textLabel.text = @"推荐给朋友";
            }else  if (indexPath.row == 2) {
                cell.textLabel.text = @"帮助";
            }else  if (indexPath.row == 3) {
                cell.textLabel.text = @"当前版本4.2";
            }else  if (indexPath.row == 4) {
                cell.textLabel.text = @"关于我们";
            }else  if (indexPath.row == 5) {
                cell.textLabel.text = @"隐私政策";
            }else{
                cell.textLabel.text = @"打分支持不得姐！";
            }
            return cell;
        }
    }
    
}

#pragma mark - 代理方法
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"功能设置";
    }else {
        return @"其他";
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([cell isKindOfClass:[LZSettingCell class]]) {
        LZLog(@"点击了设置类型的cell");
    }else if ([cell isKindOfClass:[LZOtherCell class]])
    {
        LZLog(@"点击了其他类型的cell");
    }
}

@end
